package com.jeethink.erp.stock.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.erp.stock.domain.TbEnterStock;
import com.jeethink.erp.stock.service.ITbEnterStockService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 入库单Controller
 * 
 * @author ypr
 * @date 2021-06-01
 */
@RestController
@RequestMapping("/erp/stock")
public class TbEnterStockController extends BaseController
{
    @Autowired
    private ITbEnterStockService tbEnterStockService;

    /**
     * 查询入库单列表
     */
    @PreAuthorize("@ss.hasPermi('erp:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEnterStock tbEnterStock)
    {
        startPage();
        List<TbEnterStock> list = tbEnterStockService.selectTbEnterStockList(tbEnterStock);
        return getDataTable(list);
    }

    /**
     * 导出入库单列表
     */
    @PreAuthorize("@ss.hasPermi('erp:stock:export')")
    @Log(title = "入库单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbEnterStock tbEnterStock)
    {
        List<TbEnterStock> list = tbEnterStockService.selectTbEnterStockList(tbEnterStock);
        ExcelUtil<TbEnterStock> util = new ExcelUtil<TbEnterStock>(TbEnterStock.class);
        return util.exportExcel(list, "stock");
    }

    /**
     * 获取入库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:stock:query')")
    @GetMapping(value = "/{enterStockId}")
    public AjaxResult getInfo(@PathVariable("enterStockId") Long enterStockId)
    {
        return AjaxResult.success(tbEnterStockService.selectTbEnterStockById(enterStockId));
    }

    /**
     * 新增入库单
     */
    @PreAuthorize("@ss.hasPermi('erp:stock:add')")
    @Log(title = "入库单", businessType = BusinessType.INSERT)
    @PostMapping
    @Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED,readOnly = false,rollbackFor = {Exception.class})
    public AjaxResult add(@RequestBody TbEnterStock tbEnterStock)
    {
        return toAjax(tbEnterStockService.insertTbEnterStock(tbEnterStock));
    }

    /**
     * 修改入库单
     */
    @PreAuthorize("@ss.hasPermi('erp:stock:edit')")
    @Log(title = "入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEnterStock tbEnterStock)
    {
        return toAjax(tbEnterStockService.updateTbEnterStock(tbEnterStock));
    }

    /**
     * 删除入库单
     */
    @PreAuthorize("@ss.hasPermi('erp:stock:remove')")
    @Log(title = "入库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enterStockIds}")
    public AjaxResult remove(@PathVariable Long[] enterStockIds)
    {
        return toAjax(tbEnterStockService.deleteTbEnterStockByIds(enterStockIds));
    }
}
